import {Injectable} from '@angular/core';
import {TagService} from './tag.service';
import {TagDict} from '../entity/tag-dict.model';
import {HttpClient} from '@angular/common/http';

@Injectable()
export class TagDictService {
  /**
   * 测点字典
   * 例如
   * constructor(private tagDictService:TagDictService){
     *     let power:Tag = tagDictService.getTag["Power"];
     * }
   * @type {TagDict}
   * @memberof TagDictService
   */
  public getTag: TagDict = {};

  // private tagService: TagService;

  constructor(private tagService: TagService) {

  }

  public initData(): Promise<boolean> {
    // this.tagService = new TagService(this.http);
    return this.tagService.getTagList()
      .then(res => {
        res.forEach(tag => {
          this.getTag[tag.tagKey] = tag;
        })
        return Promise.resolve(true);
      })
      .catch(this.handleError);

  }

  private handleError(error: any): Promise<any> {
    return Promise.reject(error.message || error);
  }

}


// WEBPACK FOOTER //
// ./src/app/service/tag-dict.service.ts
